// pages/myself/myself.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        islogin: true,
        functionList: [{
                id: 1,
                imageUrl: "/image/myself/zjbf.png",
                textMsg: "最近播放"
            },
            {
                id: 2,
                imageUrl: "/image/myself/yp.png",
                textMsg: "云盘"
            },
            {
                id: 3,
                imageUrl: "/image/myself/bdxz.png",
                textMsg: "本地下载"
            },
            {
                id: 4,
                imageUrl: "/image/myself/yg.png",
                textMsg: "已购"
            },
            {
                id: 5,
                imageUrl: "/image/myself/wdhy.png",
                textMsg: "我的好友"
            },
            {
                id: 6,
                imageUrl: "/image/myself/sc.png",
                textMsg: "收藏和赞"
            },
            {
                id: 7,
                imageUrl: "/image/myself/wdfs.png",
                textMsg: "我的粉丝"
            },
            {
                id: 8,
                imageUrl: "/image/myself/xh.png",
                textMsg: "喜欢"
            },
        ],
        musicList: [1, 2],
        userMsg: {
            nickName: "",
            imageUrl: "",
            username: "",
            autograph: ""

        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if (wx.getStorageSync('username')) {
            wx.request({
                url: 'http://localhost:8081/user/getUserMsg',
                data: {
                    "username": wx.getStorageSync('username')
                },
                method: "GET",
                success: (result) => {
                    // console.log(result.data);
                    const {
                        username,
                        nickName,
                        imageUrl,
                        autograph
                    } = result.data.data;
                    this.setData({
                        userMsg: {
                            "username": username,
                            "nickName": nickName,
                            "imageUrl": imageUrl,
                            "autograph": autograph,
                        },
                        islogin: false
                    });
                }
            })
        }
    },
    // 点击立即登录
    immediateLogin() {
        wx.navigateTo({
            url: '/pages/login/login',
        })
    },
    //修改信息
    changeInformation() {
        wx.navigateTo({
            url: '/pages/information/information',
        })
    },
    //退出
    quit() {
        if (wx.getStorageSync('username')) {
            wx.showModal({
                title: '提示',
                content: '确定退出吗',
                complete: (res) => {
                    if (res.cancel) {}
                    if (res.confirm) {
                        wx.removeStorageSync('username');
                        this.setData({
                            islogin: true
                        });
                        this.onLoad();
                    }
                }
            })
        }
    },
    onShow() {
        this.onLoad();
    },
    // 进入最近播放界面
    entryRecentPlay(e) {
        const {
            feld
        } = e.currentTarget.dataset;
        if (feld === 1) {
            if (wx.getStorageSync('username')) {
                wx.navigateTo({
                    url: '/pages/recentPlay/recentPlay',
                })
            }
        }
    }
})